package ysq.xyg.service.impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WebSubDao;
import ysq.xyg.model.WebSub;
import ysq.xyg.service.WebSubService;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("webSubService")
public class WebSubServiceImpl extends BaseServiceImpl<WebSub> implements WebSubService {
    @Resource
    private WebSubDao webSubDao;

    @Autowired
    public void setBaseDao(WebSubDao webSubDao) {
        this.baseDao = webSubDao;
    }

    @Override
    public PageInfo<WebSub> pageInfo(WebSub webSub, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        List<WebSub> list=list(webSub);
        return new PageInfo<WebSub>(list);
    }
    @Override
    public List<WebSub> list(WebSub webSub) {
        //通用Example查询
        Example example = new Example(WebSub.class);
        Example.Criteria criteria = example.createCriteria();
        if(webSub!=null){
            if(StrUtil.isNotEmpty(webSub.getCheckState())){
                criteria.andEqualTo("checkState",webSub.getCheckState());
            }
            if(StrUtil.isNotEmpty(webSub.getMemberId())){
                criteria.andEqualTo("memberId",webSub.getMemberId());
            }
            if(StrUtil.isNotEmpty(webSub.getName())){
                criteria.andLike("name","%"+webSub.getName()+"%");
            }
            if(StrUtil.isNotEmpty(webSub.getPhone())){
                criteria.andLike("phone","%"+webSub.getPhone()+"%");
            }
            if(StrUtil.isNotEmpty(webSub.getSubType())){
                criteria.andEqualTo("subType",webSub.getSubType());
            }
        }
        List<WebSub> list=webSubDao.selectByExample(example);
        return list;
    }
    @Override
    public WebSub selectWebSub() {
        List<WebSub> list=webSubDao.selectAll();
        if(list!=null&&list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }
}
